//用户登录
//var loginId; //dialog
//var loginformId; //formId
$(function(){
	/**
	 * 登录校验
	 */
	$("#checkId").click(function(){
		$("#loginFormId").validate({
			onsubmit:true,// 是否在提交是验证
			onfocusout:false,// 是否在获取焦点时验证
			onkeyup :false,// 是否在敲击键盘时验证
			rules: {
				username: "required",
				password: "required"
			},
			messages:{
				username:"*请输入用户名",
				password:"*请输入密码"
			},
			submitHandler: function(form) {//通过之后回调
				var userName = $("#userName").val();
				var password = $("#password").val();
			     $.ajax({
					url : $WEB_ROOT_PATH+'/w/checkLogin',
					type : "post",
					dataType : "json",
					data: {userName:userName,password:password},
					success : function(data){
						if(data.msg=="success"){
							//$.messager.progress("close");
							window.location.href=$WEB_ROOT_PATH+"/w/domain";
						}
						if(data.msg=="fail"){
							$.messager.alert("提示","用户名或密码错误！","",function(){
								window.location.href=$WEB_ROOT_PATH+"/w/login";
							});
						}
					}
			     });
			},
			invalidHandler: function(form, validator) {  //不通过回调
				return false;
			}
		});
	});
	//表单验证
	/*function check(){
		if($("#checkId").form('validate')){
			var username = $("#username").val();
			var password = $("#password").val();*/
			/*$.messager.progress({
				text:"正在登录中。。。",
				interval:300
			});*/
			/*$.post($WEB_ROOT_PATH+'/w/checkLogin',{username:username,password:password},function(data){
				if(data.msg=="success"){
					//$.messager.progress("close");
					window.location.href=$WEB_ROOT_PATH+"/w/domain";
				}
				if(data.msg=="fail"){
					$.messager.alert("提示","用户名或密码错误！","",function(){
						window.location.href=$WEB_ROOT_PATH+"/w/login";
					});
				}*/
				/*
				if(data.msg=="state"){
					$.messager.progress("close");
					$.messager.alert("提示","该用户已被禁用！","",function(){
						//window.location="index.jsp";
						window.location="login.html";
					});
				}
				if(data.msg=="final"){
					$.messager.progress("close");
					$.messager.alert("提示","该用户已被删除！","",function(){
						//window.location="index.jsp";
						window.location="login.html";
					});
				}
				if(data.msg=="all"){
					$.messager.progress("close");
					$.messager.alert("提示","该用户已不存在！","",function(){
						//window.location="index.jsp";
						window.location="login.html";
					});
				}*/
			/*},'json');
		}
	}*/
	
	//注销登录
	$("#logoutId").click(function(){
		$.messager.confirm("提示", "您确定要注销当前登录吗？", function(flag) {
			if(flag){
				$.post($WEB_ROOT_PATH+'/w/layout',function(data){
					window.location=$WEB_ROOT_PATH+"/w/login";
					
				});
			}
		});
	});
});